home *** CD-ROM | disk | FTP | other *** search
/ The World's Largest Collection of Windows Software / The World's Largest Collection of Windows Software - Disc 1.iso / connect / _j2 / wvnsc926 / rcs / wvmapi.c < prev    next >
C/C++ Source or Header  |  1994-09-21  |  13KB  |  659 lines

  1. head     1.11;
  2. branch   ;
  3. access   ;
  4. symbols  V80:1.4;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.11
  10. date     94.09.19.07.52.52;  author jcooper;  state Exp;
  11. branches ;
  12. next     1.10;
  13.  
  14. 1.10
  15. date     94.01.24.17.41.01;  author jcoop;  state Exp;
  16. branches ;
  17. next     1.9;
  18.  
  19. 1.9
  20. date     93.12.08.01.28.38;  author rushing;  state Exp;
  21. branches ;
  22. next     1.8;
  23.  
  24. 1.8
  25. date     93.08.25.18.54.36;  author mbretherton;  state Exp;
  26. branches ;
  27. next     1.7;
  28.  
  29. 1.7
  30. date     93.06.28.17.52.17;  author rushing;  state Exp;
  31. branches ;
  32. next     1.6;
  33.  
  34. 1.6
  35. date     93.06.22.19.44.16;  author rushing;  state Exp;
  36. branches ;
  37. next     1.5;
  38.  
  39. 1.5
  40. date     93.06.22.15.36.05;  author dumoulin;  state Exp;
  41. branches ;
  42. next     1.4;
  43.  
  44. 1.4
  45. date     93.06.11.00.10.35;  author rushing;  state Exp;
  46. branches ;
  47. next     1.3;
  48.  
  49. 1.3
  50. date     93.05.18.22.11.40;  author rushing;  state Exp;
  51. branches ;
  52. next     1.2;
  53.  
  54. 1.2
  55. date     93.04.30.22.08.01;  author rushing;  state Exp;
  56. branches ;
  57. next     1.1;
  58.  
  59. 1.1
  60. date     93.03.30.21.08.58;  author rushing;  state Exp;
  61. branches ;
  62. next     ;
  63.  
  64.  
  65. desc
  66. @MAPI merge
  67. @
  68.  
  69.  
  70. 1.11
  71. log
  72. @Massive cleanup for 92.6
  73. @
  74. text
  75. @/* ---- WVMAPI.C ---------------------------------------------- 
  76.  *
  77.  *  This file contains the porocedures required for the MAPI
  78.  *  (MS Mail) interface
  79.  *
  80.  *  MAtthew Bretherton     18/2/1993
  81.  */
  82.  
  83.  
  84. /*
  85.  * $Id: wvmapi.c 1.11 1994/09/16 00:48:47 jcooper Exp $
  86.  * $Log: wvmapi.c $
  87.  * Revision 1.10  1994/01/24  17:41:01  jcoop
  88.  * 90.2 changes
  89.  *
  90.  * Revision 1.9  1993/12/08  01:28:38  rushing
  91.  * new version box and cr lf consistency
  92.  *
  93.  * Revision 1.8  1993/08/25  18:54:36  mbretherton
  94.  * MRB merge, mail & post logging
  95.  *
  96.  * Revision 1.8  1993/08/04 Bretherton
  97.  * re reverse maildemandlogon (and change default in winvn.c)
  98.  * to match comms dialog box settings (and consequent logic)
  99.  * apologies Sam
  100.  * Revision 1.7  1993/06/28  17:52:17  rushing
  101.  * fixed compiler warnings
  102.  *
  103.  * Revision 1.6  1993/06/22  19:44:16  rushing
  104.  * reverse logic of MailDemandLogon
  105.  *
  106.  * Revision 1.5  1993/06/22  15:36:05  dumoulin
  107.  * Don't display MAPI error message when a user cancels his/her own message
  108.  *
  109.  * Revision 1.4  1993/06/11  00:10:35  rushing
  110.  * second merge from Matt Bretherton sources
  111.  *
  112.  *
  113.  * Revision 1.3  1993/05/18  22:11:40  rushing
  114.  * smtp support
  115.  *
  116.  * Revision 1.2  1993/04/30  22:08:01  rushing
  117.  * removed newbie-frightening messageboxes
  118.  *
  119.  * Revision 1.1  1993/03/30  21:08:58  rushing
  120.  * Initial revision
  121.  *
  122.  *
  123.  */
  124.  
  125. #include <windows.h>
  126. #include <windowsx.h>
  127. #include "wvglob.h"
  128. #include "winvn.h"
  129. #pragma hdrstop
  130. #include "mapi.h"
  131. #include "wvmapi.h"
  132.  
  133.  HINSTANCE hLibrary = 0;
  134.  ULONG ulResult  ;
  135.  LHANDLE hMAPISession  ;
  136.  FLAGS flFlag = 0L;
  137.  BOOL LoggedOn  ;           // required for demand login
  138.  char buf[MAXOUTLINE];
  139.  char mess[MAXOUTLINE];
  140.  
  141.  mlMAPIInit (HWND hWnd)
  142.  {
  143. /*   MessageBox (hWnd, "MS MAil Initialisation", "Debug!", MB_OK | MB_ICONHAND); */
  144.    LoggedOn = FALSE ;
  145.  
  146.  
  147.    if ( InitMAPI() ) 
  148.        {
  149. // this is confusing to newbies
  150. //       MessageBox (hWnd, "Error in Initialisation\r\nMail Interface Disabled", "Microsoft Mail", MB_OK | MB_ICONHAND);
  151.        return (-1) ;
  152.     };
  153.  
  154.   if (MailDemandLogon) return (0)  ;
  155.   else  return (mlMAPILogon(hWnd)) ;
  156.  }
  157.  
  158. int
  159.  mlMAPILogon (HWND hWnd)
  160.  {
  161.   flFlag = MAPI_LOGON_UI;
  162.  
  163.   ulResult = (ULONG)(*lpfnMAPILogon)((ULONG) hWnd, NULL, NULL, flFlag, 0L, (LPLHANDLE)&hMAPISession);
  164.   if( ulResult != 0)
  165.        {
  166. // this is confusing to newbies
  167. //       sprintf(mess,"Failure to Login\r\nMail Interface Disabled\r\nError = %ld",ulResult);
  168. //       MessageBox (hWnd,mess , "Microsoft Mail", MB_OK | MB_ICONHAND);
  169.        return (-1) ;
  170.        }   
  171.    LoggedOn = TRUE ;
  172.    MailEnableLogout(LoggedOn);
  173.    return(0) ;
  174.  }
  175.  
  176. /* -------- mlMAPILogout ---------------
  177.  *
  178.  * Logout from MAPI service but leave resources available
  179.  * (loaded)
  180.  *
  181.  * --------------------------------------*/
  182.  
  183.  mlMAPILogout (hWnd)
  184.     HWND hWnd;
  185.  {
  186. /*   MessageBox (hWnd, "MS MAil Logout", "Debug!", MB_OK | MB_ICONHAND); */
  187.    ulResult =(ULONG)(*lpfnMAPILogoff)(hMAPISession,(ULONG) hWnd, 0L, 0L) ;
  188.    if (ulResult==0)
  189.    {
  190.       LoggedOn = FALSE ;
  191.       MailEnableLogout(LoggedOn);
  192.       return(0);
  193.    }
  194.    return(-1) ;
  195.  }
  196.  
  197. /* -------- mlMAPIClose ---------------
  198.  *
  199.  * Remove all trace of MAPI services - log out (if necessary)
  200.  * and unload resources
  201.  *
  202.  * --------------------------------------*/
  203.  
  204.  mlMAPIClose (HWND hWnd)
  205. {  if (LoggedOn) mlMAPILogout(hWnd) ;
  206.    DeInitMAPI();
  207.    return(0) ;
  208. }
  209.  
  210. /******** mlMAPISend *************************************************** 
  211.  *   
  212.  *  Send Mail for MAPI Interface 
  213.  *
  214.  *
  215.  */
  216.  
  217.  mlMAPISend (hWnd ,Doc, DocType )
  218.    HWND hWnd;
  219.    TypDoc *Doc;
  220.    int DocType;
  221.  {
  222.  static  MapiMessage mmMapiMessage;
  223.  static  MapiRecipDesc recips;     /* Recipients 
  224.                     - only one To: at present */
  225.  /*  Not yet required 
  226.    MapiFileDesc files[2];
  227.  */
  228.    HANDLE hMemBuf ;
  229.    char Address[MAXDIALOGSTRING] ;
  230.    char far *mBuf;
  231.  
  232.    if (!LoggedOn)
  233.    { 
  234.      if( ! mlMAPILogon(hWnd) == 0 ) 
  235.      { // No Logon - No Go !
  236.     return(-1) ;
  237.      } 
  238.    }
  239.  
  240.    if (NULL == (hMemBuf = ExtractPostingText(Doc,DocType)))
  241.     {
  242.       MessageBox (hWnd, "Cannot allocate memory for text", "", MB_OK);
  243.       return FALSE;
  244.     }
  245.    mBuf=GlobalLock(hMemBuf) ;
  246.  
  247.   if (strchr(AddressString,'@@') != NULL)
  248.      {
  249.        sprintf(Address,"SMTP:%s",AddressString) ;
  250.      }
  251.   else
  252.      {
  253.      strcpy(Address,AddressString) ;
  254.      }
  255. /*  mrb debugging   
  256.   MessageBox (hWnd, Address, "Address", MB_OK | MB_ICONHAND);
  257.   MessageBox (hWnd, NameString, "Name", MB_OK | MB_ICONHAND);
  258.   MessageBox (hWnd, DialogString, "Subject", MB_OK | MB_ICONHAND);
  259.   MessageBox (hWnd, mBuf, "Article", MB_OK | MB_ICONHAND);
  260. */
  261.  /* need to build mmMApiMessage
  262.        multiple recipients 
  263.        and a copies command */ 
  264.  
  265.   if (!strcmp(DialogString,""))
  266.      {
  267.        mmMapiMessage.lpszSubject = NULL ;
  268.       }
  269.   else
  270.      { 
  271.        mmMapiMessage.lpszSubject = DialogString ;
  272.       }
  273.   if (!strcmp(mBuf,""))
  274.       {
  275.          mmMapiMessage.lpszNoteText = NULL ;
  276.       }
  277.   else
  278.       {
  279.     mmMapiMessage.lpszNoteText = mBuf;
  280.        }
  281.  
  282.  /*  should parse Addressee and Copies to fill lpRecips 
  283.     use MAPI_CC  for copies                             */ 
  284.  
  285.  
  286.  if (!strcmp(Address,""))
  287.      {
  288.        mmMapiMessage.nRecipCount = 0L ;
  289.        mmMapiMessage.lpRecips=NULL ;
  290.  
  291.      }
  292.   else
  293.      {
  294.        mmMapiMessage.nRecipCount = 1L ;
  295.        recips.ulReserved = 0L ;
  296.        recips.lpszAddress =  Address  ;
  297.        recips.ulRecipClass = MAPI_TO ;
  298.        recips.lpszName =  NameString  ;
  299.        recips.ulEIDSize = 0L ;
  300.        recips.lpEntryID = NULL ;
  301.        mmMapiMessage.lpRecips=&recips ;
  302.      }
  303.  
  304.  
  305.   mmMapiMessage.ulReserved = 0L;
  306.   mmMapiMessage.lpszMessageType = NULL;
  307.   mmMapiMessage.lpszDateReceived = NULL;
  308.   mmMapiMessage.lpszConversationID = NULL ;
  309.   mmMapiMessage.flFlags = 0L;
  310.   mmMapiMessage.lpOriginator = NULL;
  311.   mmMapiMessage.nFileCount = 0L;
  312.   mmMapiMessage.lpFiles = NULL;
  313.  
  314.   flFlag =MAPI_DIALOG;   /* MAPI_DIALOG shows a windows for message
  315.                 editing , addressing etc.
  316.                 MAPI_LOGON_UI in helpreq.c example  */
  317.   ulResult = (ULONG)(*lpfnMAPISendMail)(hMAPISession, (ULONG) hWnd, &mmMapiMessage, 
  318.          flFlag, 0L);
  319.   FreePostingText (hMemBuf) ;
  320.   MailEdit = (WndEdit *) NULL;
  321.  
  322.   if ( ulResult > 1 )
  323.     {
  324.        sprintf(buf,"MS MAil Error - No. %u",ulResult) ;
  325.        MessageBox (hWnd, buf, "Microsoft Mail Send", MB_OK | MB_ICONHAND);
  326.        return(-1) ;
  327.      } ;
  328.  
  329.   return(0) ;
  330.  
  331.  }
  332.  
  333.  
  334. /* Following code extracted from Microsofts MAPI Sample 
  335.    MAPIAPP.C on the MS MAIL 3.0 distibution disks */
  336.  
  337. int FAR PASCAL InitMAPI()
  338. {
  339.   char *libraryName;
  340.           
  341.   if ((hLibrary = LoadLibrary(MAPIDLL)) < HINSTANCE_ERROR)
  342.     return(ERR_LOAD_LIB);
  343.  
  344.   if (((FARPROC)lpfnMAPILogon = GetProcAddress(hLibrary,SZ_MAPILOGON)) == NULL)
  345.     return(ERR_LOAD_FUNC);
  346.  
  347.   if (((FARPROC)lpfnMAPILogoff= GetProcAddress(hLibrary,SZ_MAPILOGOFF)) == NULL)
  348.     return(ERR_LOAD_FUNC);
  349.  
  350.   if (((FARPROC)lpfnMAPISendMail= GetProcAddress(hLibrary,SZ_MAPISENDMAIL)) == NULL)
  351.     return(ERR_LOAD_FUNC);
  352.  
  353.   if (((FARPROC)lpfnMAPIAddress= GetProcAddress(hLibrary,SZ_MAPIADDRESS)) == NULL)
  354.     return(ERR_LOAD_FUNC);
  355.  
  356.   if (((FARPROC)lpfnMAPIFreeBuffer= GetProcAddress(hLibrary,SZ_MAPIFREEBUFFER)) == NULL)
  357.     return(ERR_LOAD_FUNC);
  358.  
  359.   /* Following Functions are not required 
  360.  
  361.   if ((lpfnMAPISendDocuments= GetProcAddress(hLibrary,SZ_MAPISENDDOC)) == NULL)
  362.     return(ERR_LOAD_FUNC);
  363.  
  364.   if ((lpfnMAPIFindNext= GetProcAddress(hLibrary,SZ_MAPIFINDNEXT)) == NULL)
  365.     return(ERR_LOAD_FUNC);
  366.  
  367.   if ((lpfnMAPIReadMail= GetProcAddress(hLibrary,SZ_MAPIREADMAIL)) == NULL)
  368.     return(ERR_LOAD_FUNC);
  369.  
  370.   if ((lpfnMAPISaveMail= GetProcAddress(hLibrary,SZ_MAPISAVEMAIL)) == NULL)
  371.     return(ERR_LOAD_FUNC);
  372.  
  373.   if ((lpfnMAPIDeleteMail= GetProcAddress(hLibrary,SZ_MAPIDELMAIL)) == NULL)
  374.     return(ERR_LOAD_FUNC);
  375.  
  376.   if ((lpfnMAPIDetails= GetProcAddress(hLibrary,SZ_MAPIDETAILS)) == NULL)
  377.     return(ERR_LOAD_FUNC);
  378.  
  379.   if ((lpfnMAPIResolveName= GetProcAddress(hLibrary,SZ_MAPIRESOLVENAME)) == NULL)
  380.     return(ERR_LOAD_FUNC);
  381.  
  382.   */
  383.  
  384.   return(0);
  385. }
  386.  
  387.  
  388. int FAR PASCAL DeInitMAPI()
  389. {
  390.   lpfnMAPILogon = NULL;
  391.   lpfnMAPILogoff= NULL;
  392.   lpfnMAPISendMail= NULL;
  393.   lpfnMAPIFreeBuffer = NULL;
  394.   lpfnMAPIAddress= NULL;
  395.  
  396.   /* following functions are unused
  397.   lpfnMAPISendDocuments= NULL;
  398.   lpfnMAPIFindNext= NULL;
  399.   lpfnMAPIReadMail= NULL;
  400.   lpfnMAPISaveMail= NULL;
  401.   lpfnMAPIDeleteMail= NULL;
  402.   lpfnMAPIDetails = NULL;
  403.   lpfnMAPIResolveName = NULL
  404.   */
  405.  
  406.   FreeLibrary(hLibrary);
  407.  
  408.   return(0);
  409. }
  410. @
  411.  
  412.  
  413. 1.10
  414. log
  415. @90.2 changes
  416. @
  417. text
  418. @d11 1
  419. a11 1
  420.  * $Id: wvmapi.c 1.9 1993/12/08 01:28:38 rushing Exp $
  421. d13 3
  422. d51 7
  423. d59 1
  424. a59 7
  425.  #include "windows.h"
  426.  #include "mapi.h"
  427.  #include "wvglob.h"
  428.  #include "winvn.h"
  429.  #include "wvmapi.h"
  430.  
  431.  HANDLE hLibrary;
  432. d61 1
  433. a61 1
  434.  HANDLE hMAPISession  ;
  435. d89 1
  436. a89 1
  437.   ulResult = (*lpfnMAPILogon)((ULONG) hWnd, NULL, NULL, flFlag, 0L, (LPLHANDLE)&hMAPISession);
  438. d113 1
  439. a113 1
  440.    ulResult =(*lpfnMAPILogoff)(hMAPISession,(ULONG) hWnd, 0L, 0L) ;
  441. d243 1
  442. a243 1
  443.   ulResult = (*lpfnMAPISendMail)(hMAPISession, (ULONG) hWnd, &mmMapiMessage, 
  444. d265 3
  445. a267 2
  446.  
  447.   if ((hLibrary = LoadLibrary(MAPIDLL)) < 32)
  448. @
  449.  
  450.  
  451. 1.9
  452. log
  453. @new version box and cr lf consistency
  454. @
  455. text
  456. @d11 1
  457. a11 1
  458.  * $Id: wvmapi.c 1.8 1993/08/25 18:54:36 mbretherton Exp rushing $
  459. d13 3
  460. d242 1
  461. @
  462.  
  463.  
  464.  
  465. 1.8
  466. log
  467. @MRB merge, mail & post logging
  468. @
  469. text
  470. @d9 1
  471. d11 1
  472. a11 1
  473.  * $Id: wvmapi.c 1.7 1993/06/28 17:52:17 rushing Exp $
  474. d13 3
  475. @
  476.  
  477.  
  478.  
  479. 1.7
  480. log
  481. @fixed compiler warnings
  482. @
  483. text
  484. @d10 1
  485. a10 1
  486.  * $Id: wvmapi.c 1.6 1993/06/22 19:44:16 rushing Exp rushing $
  487. d12 7
  488. d69 1
  489. a69 1
  490.   if (!MailDemandLogon) return (0)  ;
  491. @
  492.  
  493.  
  494.  
  495. 1.6
  496. log
  497. @reverse logic of MailDemandLogon
  498. @
  499. text
  500. @d10 1
  501. a10 1
  502.  * $Id: wvmapi.c 1.5 1993/06/22 15:36:05 dumoulin Exp rushing $
  503. d12 3
  504. a136 1
  505.    BOOL Addressed  ;
  506. d250 1
  507. a250 1
  508.   if ((lpfnMAPILogon = GetProcAddress(hLibrary,SZ_MAPILOGON)) == NULL)
  509. d253 1
  510. a253 1
  511.   if ((lpfnMAPILogoff= GetProcAddress(hLibrary,SZ_MAPILOGOFF)) == NULL)
  512. d256 1
  513. a256 1
  514.   if ((lpfnMAPISendMail= GetProcAddress(hLibrary,SZ_MAPISENDMAIL)) == NULL)
  515. d259 1
  516. a259 1
  517.   if ((lpfnMAPIAddress= GetProcAddress(hLibrary,SZ_MAPIADDRESS)) == NULL)
  518. d262 1
  519. a262 1
  520.   if ((lpfnMAPIFreeBuffer= GetProcAddress(hLibrary,SZ_MAPIFREEBUFFER)) == NULL)
  521. @
  522.  
  523.  
  524.  
  525. 1.5
  526. log
  527. @Don't display MAPI error message when a user cancels his/her own message
  528. @
  529. text
  530. @d10 1
  531. a10 1
  532.  * $Id: wvmapi.c 1.4 1993/06/11 00:10:35 rushing Exp dumoulin $
  533. d12 3
  534. d59 1
  535. a59 1
  536.   if (MailDemandLogon) return (0)  ;
  537. @
  538.  
  539.  
  540.  
  541. 1.4
  542. log
  543. @second merge from Matt Bretherton sources
  544. @
  545. text
  546. @d10 1
  547. a10 1
  548.  * $Id: wvmapi.c 1.3 1993/05/18 22:11:40 rushing Exp $
  549. d12 2
  550. d15 1
  551. d224 1
  552. a224 1
  553.   if ( ulResult !=0 )
  554. @
  555.  
  556.  
  557.  
  558. 1.3
  559. log
  560. @smtp support
  561. @
  562. text
  563. @d10 1
  564. a10 1
  565.  * $Id: wvmapi.c 1.2 1993/04/30 22:08:01 rushing Exp rushing $
  566. d12 4
  567. d27 3
  568. a29 1
  569.  #include "mapi.h" 
  570. a30 1
  571.  #include "wvglob.h"
  572. d36 1
  573. d40 2
  574. a41 3
  575.  mlMAPIInit (hWnd) 
  576.     HWND hWnd;
  577.  { 
  578. d43 3
  579. a45 1
  580.  
  581. d52 8
  582. d70 13
  583. a82 2
  584.  } 
  585.  mlMAPILogout (hWnd)  
  586. d84 1
  587. a84 1
  588.  {  
  589. d86 16
  590. a101 2
  591.    (*lpfnMAPILogoff)(hMAPISession,(ULONG) hWnd, 0L, 0L) ;
  592.    DeInitMAPI() ;
  593. d103 5
  594. a107 1
  595.  }
  596. d132 7
  597. a139 1
  598.    
  599. d213 1
  600. a213 1
  601.   
  602. d219 2
  603. d224 1
  604. a224 1
  605.        MessageBox (hWnd, buf, "Microsoft Mail", MB_OK | MB_ICONHAND);
  606. d228 1
  607. a228 1
  608.   FreePostingText (hMemBuf) ;
  609. a287 1
  610.  
  611. @
  612.  
  613.  
  614.  
  615. 1.2
  616. log
  617. @removed newbie-frightening messageboxes
  618. @
  619. text
  620. @d10 1
  621. a10 1
  622.  * $Id: wvmapi.c 1.1 1993/03/30 21:08:58 rushing Exp rushing $
  623. d12 3
  624. d85 1
  625. a85 1
  626.    char Address[MAXSUBJECTSTRING] ;
  627. d108 1
  628. a108 1
  629.   MessageBox (hWnd, SubjectString, "Subject", MB_OK | MB_ICONHAND);
  630. d115 1
  631. a115 1
  632.   if (!strcmp(SubjectString,""))
  633. d121 1
  634. a121 1
  635.        mmMapiMessage.lpszSubject = SubjectString ;
  636. @
  637.  
  638.  
  639.  
  640. 1.1
  641. log
  642. @Initial revision
  643. @
  644. text
  645. @d10 4
  646. a13 2
  647.  * $Id$
  648.  * $Log$
  649. d15 1
  650. d38 2
  651. a39 1
  652.        MessageBox (hWnd, "Error in Initialisation\r\nMail Interface Disabled", "Microsoft Mail", MB_OK | MB_ICONHAND);
  653. d47 3
  654. a49 2
  655.        sprintf(mess,"Failure to Login\r\nMail Interface Disabled\r\nError = %ld",ulResult);
  656.        MessageBox (hWnd,mess , "Microsoft Mail", MB_OK | MB_ICONHAND);
  657. @
  658.  
  659.